package springredis.com.lei.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springredis.com.lei.entity.Article;
import springredis.com.lei.service.BlogsService;

@RestController
@RequestMapping("/originalHashUser")
@Api(tags = "原生redisTemplate Hash操作用户")
public class BlogsOriginalRedisHashController {
	@Autowired
	@Qualifier("blogsServiceOriginalHashRedisImpl")
	private BlogsService blogsService;

	@GetMapping
	@ApiOperation("根据ID获取用用户")
	public Article get(@RequestParam("id") Long id) {
		return blogsService.getById(id);
	}

	@DeleteMapping
	@ApiOperation("根据ID获取用用户")
	public String delete(@RequestParam("id") Long id) {
		blogsService.removeById(id);
		return "success";
	}

	@PutMapping
	@ApiOperation("根据ID修改用户")
	/**
	 * RequestBody 以Json传参
	 */
	public String update(@RequestBody Article user) {
		blogsService.updateById(user);
		return "success";
	}

	@PostMapping
	@ApiOperation("根据ID添加用户")
	/**
	 * 无RequestBody 以post传统方式传参
	 */
	public String add(@RequestBody Article user) {
		blogsService.save(user);
		return "success";
	}

	@GetMapping("/getAll")
	@ApiOperation("根据ID添加用户")
	/**
	 * 无RequestBody 以post传统方式传参
	 */
	public List<Article> getAll() {
		return blogsService.listAll();
	}
}
